use serde::Serialize;
use thiserror::Error;


pub type IoErr = std::io::Error;

#[derive(Debug, Error)]
pub enum AppErr {

    #[error("io:{0}")]
    Io(#[from] IoErr),

    #[error("serial:{0}")]
    Serial(#[from] tokio_serial::Error),

    #[error("{0}")]
    Custom(&'static str),
}


impl Serialize for AppErr {

    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
        where
            S: serde::Serializer {
        serializer.serialize_str(&self.to_string())
    }
}


